<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js" type="application/javascript"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>


</head>
<body>
<div id="app">
    <todo>
        <todo-title slot="todo-title" :title="title"></todo-title>
        <todo-items slot="todo-items" :item="item" :index="index" v-for="(item, index) in todoItems" @remove="removeItems(index)"></todo-items>
    </todo>
</div>
<script type = "text/javascript">
    Vue.component('todo', {
        template: '<div> \
                       <slot name="todo-title"></slot>\
                       <ul>\
                            <slot name="todo-items"></slot>\
                       </ul>\
                </div>'
    });

    Vue.component('todo-title', {
        props: ['title'],
        template: '<h1>{{title}}</h1>'
    });

    Vue.component('todo-items', {
        props: ['item', 'index'],
        template: '<li>{{item}}<button @click="remove(index)">删除</button></li>',
        methods: {
            remove: function (index) {
                this.$emit('remove', index);
            }
        }
    });

    new Vue({
        el: '#app',
        data:{
            title: "课程列表",
            todoItems:['Linux', 'Java', 'Python']
        },
        methods: {
            removeItems: function (index) {
                this.todoItems.splice(index, 1);
            }
        }
    })
</script>
</body>
</html>